package com.schoolCommunity.controller;


import com.schoolCommunity.entity.ForIndex;
import com.schoolCommunity.entity.Information;
import com.schoolCommunity.service.ForIndexService;
import com.schoolCommunity.service.MemberService;
import com.schoolCommunity.util.RedisUtil;
import org.elasticsearch.index.engine.Engine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author YTH
 * @since 2020-10-08
 */
@CrossOrigin
@RestController
public class ForIndexController {

    @Autowired
    private ForIndexService forIndexService;


    //管理员功能，添加介绍
    //写入作者，地点名字，地点,图片描述即可
    @PostMapping("/InsertForIndex")
    public Information InsertForIndex(@RequestBody ForIndex forIndex) throws IOException {
        return forIndexService.InsertForIndex(forIndex);
    }

    //管理员功能，添加地点图片
    @PostMapping("/UploadPlacePicture/{forIndexId}")
    public Information UploadPicture(@RequestParam("file") MultipartFile file, @PathVariable("forIndexId") long forIndexId) throws IOException {
        return forIndexService.UploadPlacePicture(file, forIndexId);
    }

    //管理员功能，删除介绍
    @GetMapping("/DeleteForIndex/{id}")
    public Information DeleteForIndex(@PathVariable("id") long id) throws IOException {
        return forIndexService.DeleteForIndex(id);
    }

    //管理员功能，修改介绍
    @PostMapping("/UpdateForIndex")
    public Information UpdateForIndex(@RequestBody ForIndex forIndex) throws IOException {
        return forIndexService.UpdateForIndex(forIndex);
    }

    //获取所有数据
    @GetMapping("/GetAllForIndex")
    public Information GetAllForIndex() {
        return forIndexService.GetAllForIndex();
    }

    //点赞某一条介绍
    @GetMapping("/AddLovesForIndex/{id}/{memberId}")
    public Information AddLovesForIndex(@PathVariable("id") long id, @PathVariable("memberId") long memberId) {
        return forIndexService.AddLovesForIndex(id, memberId);
    }


}

